/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * RSArrayElement.h
 *
 *  Created on: 2010/02/24
 *      Author: Alexandre Pires ( c.alexandre.pires@gmail.com )
 */

#ifndef RSARRAYELEMENT_H_
#define RSARRAYELEMENT_H_

#include "RSDataSource.h"

namespace Realsphere {

    class RSArrayElement: public Realsphere::RSDataSource {
        Q_OBJECT
        Q_PROPERTY( QString _attr_name READ Name WRITE SetName )
        Q_PROPERTY( int _attr_count READ Count )
        public:
            RSArrayElement ( const QString& rId = QString::null,
                    const QString& rName = QString::null,
                    const QString& rTag = RS_ARRAY_ELEMENT_TAG );

        public:

            virtual RSArrayElementType      ArrayType () const = 0;
            virtual int                     Count () const = 0;
            virtual RSDataPointer           DataPointer () = 0;
            virtual RSDataSize              SizeOf () const = 0;
            virtual QString                 ToString () const = 0;

            bool                            IsRootElement() const;

        public slots:
            virtual void                    Clear( bool rEmit = true ) = 0;
            virtual void                    Append ( const RSValueElement& rValue, bool rEmit = true ) = 0;
            virtual void                    Remove ( unsigned int rIndex, bool rEmit = true ) = 0;
            virtual void                    Remove ( unsigned int rIndex, unsigned int rSize, bool rEmit = true ) = 0;
            virtual void                    SetValue ( unsigned int rIndex, const RSValueElement& rValue, bool rEmit = true ) = 0;

        signals:
            void                            DataAdded ( const RSValueElement& rValue );
            void                            DataAdded ( unsigned int rSize );
            void                            DataRemoved ( unsigned int rIndex );
            void                            DataRemoved ( unsigned int rIndex, unsigned int rSize );
            void                            DataCleared ();
            void                            DataChanged ( unsigned int rIndex, const RSValueElement& rValue );

        protected:
            virtual RSError                 BeforeAddChildElement ( Realsphere::RSElement* rElement );

        protected:
            void                            WriteElementData ( QXmlStreamWriter* rXmlWriter );
    };

}

#endif /* RSARRAYELEMENT_H_ */
